<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.username"
        placeholder="用户名"
        style="width: 120px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.storeId"
        placeholder="商店ID"
        style="width: 120px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.storeName"
        placeholder="商店名"
        style="width: 120px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="商店ID" prop="id" min-width="16%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.store_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商店名" min-width="18%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.store_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属用户" min-width="15%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.user_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分数" min-width="15%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.value }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设置时间" min-width="20%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.opt_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作用户" min-width="16%" align="center">
        <template slot-scope="{row}">
          <span>{{ row.opt_user_name }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { fetchList } from '@/api/score'
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination'

export default {
  name: 'Score',
  components: { Pagination },
  data() {
    return {
      dialogExcelVisible: false,
      listLoading: false,
      total: 0,
      list: [],
      listQuery: {
        page: 1,
        limit: 20,
        storeId: undefined,
        storeName: undefined,
        username: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter() { this.getList() },
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.list.map(item => {
          item.opt_time = item.opt_time ? parseTime(item.opt_time) : '-'
          return item
        })
        this.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>
